package com.partsoft.dits.ldap;

/**
 * LDAP绑定验证类型
 */
public enum LdapBindAuthenticationType {

	// 不验证
	none("不验证", 0),

	// 用户DN与明文密码
	simple("简单验证(明文密码)", 1),

	// 用户DN加MD5(SSL)或GSSAPI(Kerberos)，暂时不支持
	strong("复杂验证(加密密码)", 2);

	private String title;

	private int code;

	private LdapBindAuthenticationType(String title, int code) {
		this.title = title;
		this.code = code;
	}

	public String getTitle() {
		return title;
	}

	public int getCode() {
		return code;
	}

	public static LdapBindAuthenticationType fromCode(int code) {
		for (LdapBindAuthenticationType type : LdapBindAuthenticationType.values()) {
			if (type.code == code)
				return type;
		}
		return null;
	}

	public static LdapBindAuthenticationType fromName(String name) {
		for (LdapBindAuthenticationType type : LdapBindAuthenticationType.values()) {
			if (type.name().equals(name))
				return type;
		}
		return null;
	}
	
}
